package com.lyf.scm.admin.api.controller;


import com.lyf.scm.admin.api.dto.SalesPlanDirectlyDTO;
import com.lyf.scm.admin.domain.service.SalesPlanDirectlyService;
import com.lyf.scm.common.model.ExcelExportDTO;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * description:
 * 直营预测计划
 *
 * @author: haodong
 * @data: 2020/8/3 10:23
 */
@Slf4j
@Api(tags = "直营预测计划")
@RequestMapping("/api/v1/salesPlanDirectly")
@RomeController
public class SalesPlanDirectlyController {

    @Resource
    private SalesPlanDirectlyService salesPlanDirectlyService;

    @PostMapping("/list")
    @ApiOperation(value = "按条件查询直营预测计划")
    public Response listWeekBySelective(@RequestBody SalesPlanDirectlyDTO salesPlanDirectly) {
        return Response.builderSuccess(salesPlanDirectlyService.listBySelective(salesPlanDirectly));
    }

    @PostMapping("/listAll")
    @ApiOperation(value = "查询全部直营预测计划")
    public Response listAllByCycles(@RequestBody SalesPlanDirectlyDTO salesPlanDirectly) {
        return Response.builderSuccess(salesPlanDirectlyService.listAllByCycles(salesPlanDirectly));
    }

    @PostMapping("/updateConfirm")
    @ApiOperation(value = "更新确认量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "unitType", value = "单位类型", required = true, paramType = "query", dataType = "long"),
    })
    public Response update(@RequestBody List<SalesPlanDirectlyDTO> directly, @RequestParam Long unitType) {
        return Response.builderSuccess(salesPlanDirectlyService.update(directly, unitType));
    }

    @PostMapping("/importVerification")
    @ApiOperation("导入Excel")
    public Response importVerification(@RequestBody MultipartFile file, @RequestParam("unitType") Long unitType) {
        return Response.builderSuccess(salesPlanDirectlyService.importVerification(file, unitType));
    }

    @PostMapping("/exportExcel")
    @ApiOperation("导出Excel")
    public Response exportExcel(@Valid @RequestBody ExcelExportDTO excelExportDTO, @RequestParam Integer type){
        return Response.builderSuccess(salesPlanDirectlyService.export(excelExportDTO, type));
    }
}
